﻿@page "/Pies/OutLabels"
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore.SkiaSharpView.Extensions
@using LiveChartsCore.SkiaSharpView.Painting
@using SkiaSharp

<PieChart
	Series="Series"
    IsClockwise="false"
    InitialRotation="-90">
</PieChart>

@code {
    private ISeries[] Series { get; set; }

    protected override void OnInitialized()
    {
        var index = 0;
        string[] names = ["Maria", "Susan", "Charles", "Fiona", "George"];

        Series = new[] { 8, 6, 5, 3, 3 }.AsPieSeries((value, series) =>
        {
            series.Name = names[index++ % names.Length];
            series.DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer;
            series.DataLabelsSize = 15;
            series.DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30));
            series.DataLabelsFormatter =
               point =>
                   $"This slide takes {point.Coordinate.PrimaryValue} " +
                   $"out of {point.StackedValue!.Total} parts";
            series.ToolTipLabelFormatter = point => $"{point.StackedValue!.Share:P2}";
        });
    }
}
